package SpringProject.Action;

import SpringProject.Domain.Person;
import SpringProject.Utils.RedisTemplateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.util.WebUtils;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

@Controller
@ResponseBody
//@RestController
public class HelloWorld {
    @Autowired
    private RedisTemplateUtils redisTemplateUtils;

    @GetMapping("/hello")
    public String helloWorld(HttpServletRequest request) {
        System.out.println("========" + request.getRequestURI());
        System.out.println("========" + request.getRequestURL());
        System.out.println("========" + request.getContextPath());
        System.out.println("========" + request.getServletPath());
        return "hello World";
    }

    @GetMapping("/redistemplate")
    public String redisTemplate() {
        Person p = new Person();
        p.setUserName("zhaohui");
        p.setBoss(true);
        List<Person> list=new ArrayList<>();
        list.add(p);
        redisTemplateUtils.hSet("user", "zhaohui", p);
        Person p1 = (Person) redisTemplateUtils.hGet("user", "zhaohui");
        System.out.println(p1);
        return "redistemplate";
    }
}
